import * as React from "react"
import { type SearchParams } from "@/types/table"

import { Skeleton } from "@/components/ui/skeleton"
import { DataTableSkeleton } from "@/components/data-table/data-table-skeleton"
import { Shell } from "@/components/shell"
import { getProjectGtcList } from "@/lib/project-gtc/service"
import { projectGtcSearchParamsSchema } from "@/lib/project-gtc/validations"
import { ProjectGtcTable } from "@/lib/project-gtc/table/project-gtc-table"
import { InformationButton } from "@/components/information/information-button"
interface IndexPageProps {
  searchParams: Promise<SearchParams>
}

export default async function IndexPage(props: IndexPageProps) {
  const searchParams = await props.searchParams
  const search = projectGtcSearchParamsSchema.parse(searchParams)

  const promises = Promise.all([
    getProjectGtcList({
      page: search.page,
      perPage: search.perPage,
      search: search.search,
      sort: search.sort,
    }),
  ])

  return (
    <Shell className="gap-2">
      <div className="flex items-center justify-between space-y-2">
        <div className="flex items-center justify-between space-y-2">
          <div>
            <div className="flex items-center gap-2">
              <h2 className="text-2xl font-bold tracking-tight">
                Project GTC 관리
              </h2>
              <InformationButton pagePath="evcp/project-gtc" />
            </div>
            {/* <p className="text-muted-foreground">
              프로젝트별 GTC(General Terms and Conditions) 파일을 관리할 수 있습니다. 
              각 프로젝트마다 하나의 GTC 파일을 업로드할 수 있으며, 파일 업로드 시 기존 파일은 자동으로 교체됩니다.
            </p> */}
          </div>
        </div>
      </div>

      <React.Suspense fallback={<Skeleton className="h-7 w-52" />}>
        {/* 추가 기능이 필요하면 여기에 추가 */}
      </React.Suspense>
      
      <React.Suspense
        fallback={
          <DataTableSkeleton
            columnCount={8}
            searchableColumnCount={1}
            filterableColumnCount={2}
            cellWidths={["3rem", "3rem", "12rem", "20rem", "10rem", "20rem", "15rem", "12rem", "3rem"]}
            shrinkZero
          />
        }
      >
        <ProjectGtcTable promises={promises} />
      </React.Suspense>
    </Shell>
  )
} 